;;; GNU Guix --- Functional package management for GNU
;;; Copyright   2021 Julien Lepiller <julien@lepiller.eu>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (guixrus packages common java)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix gexp)
  #:use-module (guix utils)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (guix build-system ant)
  #:use-module (gnu packages)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-26)
  #:use-module (ice-9 match))

(define-public java-jvnet-parent-pom
  (hidden-package
    (package
      (name "java-jvnet-parent-pom")
      (version "5")
      (source (origin
                (method url-fetch)
                (uri (string-append "https://repo1.maven.org/maven2/net/java/"
                                    "jvnet-parent/" version "/jvnet-parent-"
                                    version ".pom"))
                (sha256
                 (base32
                  "02nbr5jk9ynaaky5zzbdb8m3dc2yj7bzn0njl3wngayxv7w9kxhs"))))
      (build-system ant-build-system)
      (arguments
       (list
         #:tests? #f
         #:phases
         #~(modify-phases %standard-phases
             (delete 'unpack)
             (delete 'configure)
             (delete 'build)
             (replace 'install
               (install-pom-file #$(package-source this-package))))))
      (home-page "https://mvnrepository.com/artifact/net.java/jvnet-parent")
      (synopsis "Java.net parent pom")
      (description "This package contains the Java.net parent pom file.")
      (license license:asl2.0))))

(define-public java-javax-websocket-api-client
  (package
    (name "java-javax-websocket-api-client")
    (version "1.1")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://github.com/javaee/websocket-spec")
                    (commit version)))
              (file-name (git-file-name name version))
              (sha256
               (base32
                "0akvr078amiy1rypcjfxbr0gfj2q0qiyb7fc7xhiq4ajiy58d13k"))))
    (build-system ant-build-system)
    (arguments
     `(#:tests? #f; no tests
       #:jar-name ,(string-append name ".jar")
       #:source-dir "api/client/src/main/java"
       #:phases
       (modify-phases %standard-phases
         (replace 'install (install-from-pom "api/client/pom.xml"))
         (add-after 'install 'install-parent (install-pom-file "api/pom.xml")))))
    (propagated-inputs (list java-jvnet-parent-pom))
    (home-page "https://github.com/javaee/websocket-spec")
    (synopsis
     "Websocket in Java")
    (description
     "This package defines a set of Java APIs for the development of websocket
applications.")
    (license license:cddl1.1)))

(define-public java-javax-websocket-api-server
  (package
    (inherit java-javax-websocket-api-client)
    (name "java-javax-websocket-api-server")
    (arguments
     `(#:tests? #f; no tests
       #:jar-name ,(string-append name ".jar")
       #:source-dir "api/server/src/main/java"
       #:phases
       (modify-phases %standard-phases
         (replace 'install (install-from-pom "api/server/pom.xml")))))
    (propagated-inputs (list java-javax-websocket-api-client))))
